package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.OtherStudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
    OtherStudentDao studentDao = new OtherStudentDao();

    public boolean isExists(String id) {
        Student[] stu = studentDao.findAllStudent();
        //假设ID在数组中不存在
        boolean exists = false;
        //遍历数组，对每一个学生对象进行判断
        for (int i = 0; i < stu.length; i++) {
            Student student = stu[i];
            if (student != null && student.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public boolean addStudent(Student st) {
        return studentDao.addStudent(st);
    }

    public Student[] findAllStudent() {
        Student[] stus = studentDao.findAllStudent();
        //判断数组中有没有信息（有：返回数组地址，没有：返回null;）
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            //有信息
            return stus;
        } else {
            //没有信息
            return null;
        }

    }

    public void deleteStudentByld(String id) {
      studentDao.deleteStudentByld(id);

    }

    public void updateStudent(String id1, Student st) {
        studentDao.updateStudent(id1, st);
    }
}

